/// <reference path="3rd/jquery.d.ts" />

/// <reference path="3rd/chrome.d.ts" />

function buildDataObject() {
    var data = { rows: [] };
    var tablebody = $('tbody[dojoattachpoint=_tableBody]');
    var rows = tablebody.children('tr');
    for (var i = 0; i < rows.length; i++) {
        data.rows[i] = $('<div></div>').append($(rows[i]).clone()).html();
    }
    return data;
}

function initialize() {
    var menuContainer = $('span[dojoattachpoint=_simpleToolbarContainer]');
    if (menuContainer.length == 0 || menuContainer.find('#rtcPluginMenu').length != 0) {
    } else {
        var pluginMenu = $('<span id="rtcPluginMenu" class="plugin_menu"></span>');

        var viewScrumCards = $('<div class="icon gear fn"></div>');
        viewScrumCards.on('click', function () {
            chrome.extension.sendMessage({
                command: "print",
                data: buildDataObject()
            });
        });

        pluginMenu.append(viewScrumCards);

        menuContainer.append(pluginMenu);
    }
}

setInterval(initialize, 1000);


 